package com.jingmai.video.live.shortvideo.data.service.impl;

import com.common.enums.ResultEnum;
import com.common.exception.CommonException;
import com.jingmai.video.live.shortvideo.data.model.LkLiveVideoDataServedUserPO;
import com.jingmai.video.live.shortvideo.data.mapper.LkLiveVideoDataServedUserMapper;
import com.jingmai.video.live.shortvideo.data.service.LkLiveVideoDataServedUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* <p>
    * 维护用户表 服务实现类
    * </p>
*
* @author lying
* @since 2024-03-22
*/
@Service
    public class LkLiveVideoDataServedUserServiceImpl extends ServiceImpl<LkLiveVideoDataServedUserMapper, LkLiveVideoDataServedUserPO> implements LkLiveVideoDataServedUserService {

    /**
    * 维护用户表分页列表
    * @param param 根据需要进行传值
    * @return
    */
    @Override
    public IPage<LkLiveVideoDataServedUserPO> page(LkLiveVideoDataServedUserPO param,IPage<LkLiveVideoDataServedUserPO> pager) {

    QueryWrapper<LkLiveVideoDataServedUserPO> queryWrapper = new QueryWrapper<>();
    queryWrapper.lambda()
        // 用户主键id
                .eq(param.getCustomerId() != null, LkLiveVideoDataServedUserPO::getCustomerId, param.getCustomerId())
            // 用户名
                .eq(!StringUtils.isEmpty(param.getNickeName()), LkLiveVideoDataServedUserPO::getNickeName, param.getNickeName())
            // 编号
                .eq(!StringUtils.isEmpty(param.getSerialNo()), LkLiveVideoDataServedUserPO::getSerialNo, param.getSerialNo())
            // 0-暂停 1-启用 （是否生效用户配置倍数）
                .eq(param.getEnable() != null, LkLiveVideoDataServedUserPO::getEnable, param.getEnable())
            // 倍数 -- 播放量会根据当前点赞量 × 设置的倍数
                .eq(param.getMultiples() != null, LkLiveVideoDataServedUserPO::getMultiples, param.getMultiples())
            // 达到点赞数 
                .eq(param.getArriveCheer() != null, LkLiveVideoDataServedUserPO::getArriveCheer, param.getArriveCheer())
            // 达到点赞数时间（分钟） ---  至作品成功后起，xx分钟内到达xxx点赞量 （增量）
                .eq(param.getArriveTime() != null, LkLiveVideoDataServedUserPO::getArriveTime, param.getArriveTime())
            // 0-男,1-女
                .eq(param.getGender() != null, LkLiveVideoDataServedUserPO::getGender, param.getGender())
            // 手机号
                .eq(!StringUtils.isEmpty(param.getPhoneNumber()), LkLiveVideoDataServedUserPO::getPhoneNumber, param.getPhoneNumber())
            // 粉丝数量
                .eq(param.getFans() != null, LkLiveVideoDataServedUserPO::getFans, param.getFans())
            // 创建时间
                .eq(param.getCreateTime() != null, LkLiveVideoDataServedUserPO::getCreateTime, param.getCreateTime())
            // 更新时间
                .eq(param.getUpdateTime() != null, LkLiveVideoDataServedUserPO::getUpdateTime, param.getUpdateTime())
            // 数据创建人id
                .eq(param.getCreatorId() != null, LkLiveVideoDataServedUserPO::getCreatorId, param.getCreatorId())
            // 数据更新者
                .eq(!StringUtils.isEmpty(param.getUpdator()), LkLiveVideoDataServedUserPO::getUpdator, param.getUpdator())
    ;
    return  page(pager, queryWrapper);
    }

    /**
    * 维护用户表详情
    * @param id
    * @return
    */
    @Override
    public LkLiveVideoDataServedUserPO info(Long id) {
    return getById(id);
    }

    /**
    * 维护用户表新增
    * @param param 根据需要进行传值
    * @return
    */
    @Override
    public void add(LkLiveVideoDataServedUserPO param) {
    if (!save(param)) {
    throw new CommonException(ResultEnum.BUSINESS_EXCEPTION);
    }
    }

    /**
    * 维护用户表修改
    * @param param 根据需要进行传值
    * @return
    */
    @Override
    public void modify(LkLiveVideoDataServedUserPO param) {
    if (!updateById(param)) {
    throw new CommonException(ResultEnum.BUSINESS_EXCEPTION);
    }
    }

    /**
    * 维护用户表删除(单个条目)
    * @param id
    * @return
    */
    @Override
    public void remove(Long id) {
    removeById(id);
    }

    /**
    * 维护用户表删除(多个条目)
    * @param ids
    * @return
    */
    @Override
    public void removes(List<Long> ids) {
    removeByIds(ids);
    }
    }
